#!/usr/bin/env bash

set -eo pipefail

export PGPASSWORD=${DB_PASSWORD}

until psql -h "${DB_HOST}" -p "${DB_PORT}" -U "postgres" -w -c '\l'; do
  >&2 echo "Postgres is unavailable - sleeping"
  sleep 1
done

>&2 echo "Postgres is up - executing command"

python manage.py collectstatic --noinput && python manage.py migrate && python manage.py initadmin